from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QPushButton
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon, QPixmap

class SuccessDialog(QDialog):
    """操作成功提示窗口"""
    def __init__(self, title="操作成功", content="任务已完成！", parent=None):
        super().__init__(parent)
        self.setWindowTitle(title)
        self.setFixedSize(400, 200)
        self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.CustomizeWindowHint)
        self.init_ui(content)

    def init_ui(self, content):
        """初始化界面"""
        main_layout = QVBoxLayout(self)
        main_layout.setAlignment(Qt.AlignCenter)
        main_layout.setContentsMargins(20, 20, 20, 20)
        main_layout.setSpacing(15)

        # 成功图标
        icon_label = QLabel()
        icon_label.setAlignment(Qt.AlignCenter)
        icon = QIcon.fromTheme("dialog-ok", QIcon(":/icons/ok.png"))
        pixmap = icon.pixmap(QSize(64, 64))
        icon_label.setPixmap(pixmap)
        main_layout.addWidget(icon_label)

        # 标题
        title_label = QLabel(self.windowTitle())
        title_label.setObjectName("titleLabel")
        title_label.setAlignment(Qt.AlignCenter)
        main_layout.addWidget(title_label)

        # 内容
        content_label = QLabel(content)
        content_label.setObjectName("contentLabel")
        content_label.setAlignment(Qt.AlignCenter)
        content_label.setWordWrap(True)
        main_layout.addWidget(content_label)

        # 确认按钮
        btn_layout = QHBoxLayout()
        confirm_btn = QPushButton("确定")
        confirm_btn.clicked.connect(self.accept)
        btn_layout.addStretch()
        btn_layout.addWidget(confirm_btn)
        btn_layout.addStretch()
        main_layout.addLayout(btn_layout)

        # 样式表
        self.setStyleSheet("""
            SuccessDialog {
                background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                                          stop:0 #4CAF50, stop:1 #81C784);
                border-radius: 10px;
            }
            QLabel#titleLabel {
                color: white; font-size: 20px; font-weight: bold; padding: 10px;
            }
            QLabel#contentLabel {
                color: white; font-size: 14px; padding: 5px 20px; line-height: 1.5;
            }
            QPushButton {
                background-color: white; color: #2E7D32; font-size: 14px;
                font-weight: bold; border-radius: 5px; padding: 8px 20px; margin: 10px;
            }
            QPushButton:hover { background-color: #f0f0f0; }
            QPushButton:pressed { background-color: #e0e0e0; }
        """)